package com.ruoyi.aitcommon.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.aitcommon.domain.AitDataMapping;
import com.ruoyi.aitcommon.service.IAitDataMappingService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 实体映射Controller
 * 
 * @author cli
 * @date 2021-06-19
 */
@RestController
@RequestMapping("/aitcommon/aitmapping")
public class AitDataMappingController extends BaseController
{
    @Autowired
    private IAitDataMappingService aitDataMappingService;

    /**
     * 查询实体映射列表
     */
    @PreAuthorize("@ss.hasPermi('aitcommon:aitmapping:list')")
    @GetMapping("/list")
    public TableDataInfo list(AitDataMapping aitDataMapping)
    {
        startPage();
        List<AitDataMapping> list = aitDataMappingService.selectAitDataMappingList(aitDataMapping);
        return getDataTable(list);
    }

    /**
     * 导出实体映射列表
     */
    @PreAuthorize("@ss.hasPermi('aitcommon:aitmapping:export')")
    @Log(title = "实体映射", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AitDataMapping aitDataMapping)
    {
        List<AitDataMapping> list = aitDataMappingService.selectAitDataMappingList(aitDataMapping);
        ExcelUtil<AitDataMapping> util = new ExcelUtil<AitDataMapping>(AitDataMapping.class);
        return util.exportExcel(list, "实体映射数据");
    }

    /**
     * 获取实体映射详细信息
     */
    @PreAuthorize("@ss.hasPermi('aitcommon:aitmapping:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(aitDataMappingService.selectAitDataMappingById(id));
    }

    /**
     * 新增实体映射
     */
    @PreAuthorize("@ss.hasPermi('aitcommon:aitmapping:add')")
    @Log(title = "实体映射", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AitDataMapping aitDataMapping)
    {
        return toAjax(aitDataMappingService.insertAitDataMapping(aitDataMapping));
    }

    /**
     * 修改实体映射
     */
    @PreAuthorize("@ss.hasPermi('aitcommon:aitmapping:edit')")
    @Log(title = "实体映射", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AitDataMapping aitDataMapping)
    {
        return toAjax(aitDataMappingService.updateAitDataMapping(aitDataMapping));
    }

    /**
     * 删除实体映射
     */
    @PreAuthorize("@ss.hasPermi('aitcommon:aitmapping:remove')")
    @Log(title = "实体映射", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aitDataMappingService.deleteAitDataMappingByIds(ids));
    }
    /**
     * 导入实体映射
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @Log(title = "实体映射", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('aitcommon:aitmapping:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<AitDataMapping> util = new ExcelUtil<AitDataMapping>(AitDataMapping.class);
        List<AitDataMapping> maplist = util.importExcel(file.getInputStream());
        String message = aitDataMappingService.importAitDataMapping(maplist);
        return AjaxResult.success(message);
    }

    /**
     * 下载模板
     * @return
     */
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<AitDataMapping> util = new ExcelUtil<AitDataMapping>(AitDataMapping.class);
        return util.importTemplateExcel("实体映射");
    }
}
